package baodian;

import org.junit.Test;

/**
 * @author fance
 * @date 2018/7/23 13:44
 */
public class Speech {
   public void quickSort(int[] a, int lo, int hi) {
        if (hi <= lo) {
            return;
        }
        int j = partition(a, lo, hi);
        quickSort(a, lo, j - 1);
        quickSort(a, j + 1, hi);
    }
    public int  partition(int[] a, int lo, int hi) {
        int i = lo;
        int j =  hi + 1;
        int v = a[lo];
        while (true) {
            while (a[++i] < v) {
                if (i == hi) {
                    break;
                }
            }
            while (a[--j] > v) {
                if (j == lo) {
                    break;
                }
            }
            if (i >= j) {
                break;
            }
            swap(a,i,j);
        }
        swap(a,lo,j);
        return j;
    }
    public  void swap(int[] a, int i, int j) {
        int tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
    @Test
    public void test() {
        int[] a = {10,23,33,9,101};
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
    }
}
